﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache">  <!-- HTTP 1.1 -->
    <meta http-equiv="cache-control" content="no-cache,must-revalidate">  <!-- HTTP 1.0 -->
    <meta name="renderer" content="webkit|ie-comp|ie-stand"/> <!--优先级：极速模式，兼容模式，IE模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>扬州房产测绘业务管理系统</title>
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../../css/common.css">
    <script type="text/javascript" src="../../libs/jeasyui-181/jquery.min.js"></script>
    <script type="text/javascript" src="../../libs/jeasyui-181/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../libs/thUtil.js"></script>
    <!--<script type="text/javascript" src="../../libs/uploadapi.js"></script>-->
    <script type="text/javascript">
        var mainGrid = new UserContol();

        $(function () {
            if (UrlParm.hasParm('text')) {
                $('h1').html(UrlParm.parm('text'));
            }
            $('#search_Link').html(button.search).linkbutton({onClick: mygrid.reload});
            //获取部门下拉框中的数据
            globalAjax.thSysDeptGetDeptTree(function (res) {
                $("#deptId").combotree('loadData', res.data);
            });
            //获取用户状态数据
            $("#enable").combobox('loadData', i18n.UserStateItems);

            //获取用户类型数据
            $("#userType").combobox('loadData', i18n.UserTypeItems);
            //新增用户
            $('#insert_Link').html(button.insert).linkbutton({onClick: ajax.insert});
            //修改用户
            $('#update_Link').html(button.insert).linkbutton({onClick: ajax.update});
            //删除用户
            $('#delete_Link').html(button.insert).linkbutton({onClick: ajax.delete});
            //重置
            $('#reset_Link').html(button.reset).click(ajax.reset);
            //重置密码
            $('#resetPassword_Link').html(button.repassword).linkbutton({onClick: ajax.resetPassword});
            //重置签名
            $('#resign_Link').html(button.resign).linkbutton({onClick: ajax.resign});

            mygrid.init();
        });

        function change_photo() {
            PreviewImage($("input[name='U_PHOTOSIGNURL']")[0], 'Img', 'Imgdiv');
        }


        var ajax = {
            reset: function () {
                $('#englishLoginId').textbox('clear');
                $('#name').textbox('clear');
                $('#userType').combobox('clear');
                $('#deptId').combotree('clear');
                $('#userCode').textbox('clear');
                $('#enable').combobox('clear');
            },
            getList: function (param, success) {
                ////用户名
                if ($('#englishLoginId').textbox('getValue') != '') {
                    param.englishLoginId = $('#englishLoginId').textbox('getValue');
                }
                ////中文名
                if ($('#name').textbox('getValue') != '') {
                    param.name = $('#name').textbox('getValue');
                }
                //用户类型
                if ($('#userType').combobox('getValue') != '') {
                    param.userType = $('#userType').combobox('getValue');
                }
                //部门
                if ($('#deptId').combotree('getValue') != '') {
                    var t = $('#deptId').combotree('tree');
                    var node = t.tree('getSelected');
                    var childrenNode = t.tree('getChildren', node.target);
                    var json = [];
                    json.push(node.id);
                    for (var i = 0; i < childrenNode.length; i++) {
                        json.push(childrenNode[i].id);
                    }
                    param.deptId = json[0];
                }
                //员工编号
                if ($('#id').textbox('getValue') != '') {
                    param.id = $('#id').textbox('getValue');
                }
                //用户状态
                if ($('#enable').combobox('getValue') != '') {
                    param.enable = $('#enable').combobox('getValue');
                }
                Network.connect(window.api.userGetPageView, 'POST', param, function (res) {
                    console.log(res);
                    if (res.code === ResponseCode.OK) {
                        success(res.data);
                        //console.log(res.data);
                    }
                });
            },
            getOne: function (param, success) {
                Network.connect(window.api.userSelectView, 'POST', param, function (res) {
                    if (res.code === ResponseCode.OK) {
                        success(res.data);
                    }
                });
            },
            insert: function () {
                dlg = window.parent.$.hDialog({
                    href: window.router.userForm + '?n=' + Math.random(),
                    title: '新增用户',
                    width: 920,
                    height: 700,
                    onLoad: function () {
                        //部门结构
                        globalAjax.thSysDeptGetDeptTree(function (res) {
                            window.parent.$("#deptId").combotree('loadData', res.data);
                        });
                        //获取用户状态数据
                        window.parent.$("#U_STATUS").combobox('loadData', i18n.UserStateItems).combobox('setValue', '0');

                        //获取用户类型数据
                        window.parent.$("#U_TYPE").combobox('loadData', i18n.UserTypeItems).combobox('setValue', '1');
                        //性别
                        window.parent.$("#U_SEX").combobox('loadData', i18n.UserSexItems);

                        //增加图片选择的事件
                        window.parent.$("#U_PHOTOSIGNURL").filebox({
                            onChange: function (newValue, oldValue) {
                                Tools.imgTobase64(window.parent.$("input[name='U_PHOTOSIGNURL']")[0], function (base64) {
                                    var img = new Image();
                                    img.id = "signImg";
                                    img.src = base64;
                                    window.parent.$("#imgcontainer").empty();
                                    window.parent.$('#imgcontainer').append(img);
                                    window.parent.$("#U_PHOTOSIGNURL").filebox('clear');
                                });
                            }
                        });
                    },
                    submit: function () {
                        var isValid = window.parent.$('#form').form("validate");
                        if (isValid) {
                            var formData = window.parent.$("#form").serializeJson();
                            var files = window.parent.$("#U_PHOTOSIGNURL").filebox('files');
                            if (files.length > 0) {
                                var fileName = files[0].name;
                                var imgSrc = window.parent.$('#signImg').attr('src');
                                if (imgSrc !== '') {
                                    var base64 = imgSrc.split(',')[1];
                                    var param = {imageBase64: base64, fileName: fileName};
                                    //上传图片
                                    uploadAjax.upload(param, function (res) {
                                        console.log(res);
                                        if (res.code === ResponseCode.OK) {
                                            formData.U_PHOTOSIGNURL = res.data.httpUrl;
                                        }
                                        else {
                                            Tools.alert(res.message);
                                            return;
                                        }
                                    });
                                }
                            }

                            Network.connect(window.api.userUpdateView, 'POST', formData, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.show(res.message);
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    }
                });
            },
            update: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 0) {
                    Tools.alert('请选择需要修改的数据。');
                    return;
                }
                dlg = window.parent.$.hDialog({
                    href: window.router.userForm + '?n=' + Math.random(),
                    title: '修改用户',
                    width: 920,
                    height: 700,
                    onLoad: function () {
                        var param = {id: rows[0].id};

                        var depTreeData;
                        //部门结构
                        globalAjax.thSysDeptGetDeptTree(function (res) {
                            window.parent.$("#deptId").combotree('loadData', res.data);
                            depTreeData = res;
                        });
                        //获取用户状态数据
                        window.parent.$("#enable").combobox('loadData', i18n.UserStateItems).combobox('setValue', '0');
                        //获取用户类型数据
                        window.parent.$("#U_TYPE").combobox('loadData', i18n.UserTypeItems).combobox('setValue', '1');
                        //性别
                        window.parent.$("#sex").combobox('loadData', i18n.UserSexItems);
                        //增加图片选择的事件
                        window.parent.$("#U_PHOTOSIGNURL").filebox({
                            onChange: function (newValue, oldValue) {
                                if (newValue == '') {
                                    return;
                                }
                                Tools.imgTobase64(window.parent.$("input[name='U_PHOTOSIGNURL']")[0], function (base64) {
                                    var img = new Image();
                                    img.id = "signImg";
                                    img.src = base64;
                                    window.parent.$("#imgcontainer").empty();
                                    window.parent.$('#imgcontainer').append(img);
                                    //top.$("#U_PHOTOSIGNURL").filebox('clear');
                                });
                            }
                        });


                        var timer = setInterval(function () {
                            if (depTreeData) {
                                clearInterval(timer);
                                ajax.getOne(param, function (data) {
                                    window.parent.$('#form').form('load', data);
                                    window.parent.$('#password').validatebox("disable");
                                    window.parent.$('#englishLoginId').textbox("disable");
                                    if (data.U_PHOTOSIGNURL != null && data.U_PHOTOSIGNURL !== '') {
                                        var img = new Image();
                                        img.id = "signImg";
                                        img.src = data.U_PHOTOSIGNURL;
                                        window.parent.$("#imgcontainer").empty();
                                        window.parent.$('#imgcontainer').append(img);
                                    }
                                });
                            }
                        }, 200);

                    },
                    submit: function () {
                        var isValid = window.parent.$('#form').form("validate");
                        if (isValid) {
                            var formData = window.parent.$("#form").serializeJson();

                            var files = window.parent.$("#U_PHOTOSIGNURL").filebox('files');
                            if (files.length > 0) {
                                var fileName = files[0].name;
                                var imgSrc = window.parent.$('#signImg').attr('src');
                                if (imgSrc != '') {
                                    var base64 = imgSrc.split(',')[1];
                                    var param = {imageBase64: base64, fileName: fileName};
                                    //上传图片
                                    uploadAjax.upload(param, function (res) {
                                        console.log(res);
                                        if (res.code === ResponseCode.OK) {
                                            formData.U_PHOTOSIGNURL = res.data.httpUrl;
                                        }
                                        else {
                                            Tools.alert(res.message);
                                            return;
                                        }
                                    });
                                }
                            }

                            formData.U_LOGINNAME = window.parent.$('#englishLoginId').textbox("getValue");

                            Network.connect(window.api.userUpdateView, 'POST', formData, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.show(res.message);
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    }
                });
            },
            delete: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 1) {
                    Tools.confirm('是否确定删除该数据？', function (result) {
                        if (result) {
                            Network.connect(window.api.userDeleteView, 'POST', {id: rows[0].id}, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.show('删除成功');
                                    mygrid.reload();
                                }
                            });
                        }
                    });
                }
                else {
                    Tools.alert('请选择需要删除的数据。');
                }
            },
            resetPassword: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length === 1) {
                    Tools.confirm('重置密码后该用户需要重新登录，是否确定重置该用户密码？', function (result) {
                        if (result) {
                            Network.connect(window.api.userResetPassword, 'POST', {id: rows[0].id}, function (res) {
                                if (res.code === ResponseCode.OK) {
                                    Tools.show('重置成功');
                                    mygrid.reload();
                                }
                            });
                        }
                    });
                }
                else {
                    Tools.alert('请选择需要重置密码的用户。');
                }
            },
            resign: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length == 1) {
                    Tools.confirm('是否确定删除该用户的电子签名数据？', function (result) {
                        if (result) {
                            var formData = {USERID: rows[0].userId, U_PHOTOSIGNURL: ''};
                            Network.connect(window.api.userUpdate, 'POST', formData, function (res) {
                                if (res.code == ResponseCode.OK) {
                                    Tools.show('删除该用户的电子签名成功');
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    });
                }
                else {
                    Tools.alert('请选择需要删除电子签名的用户。');
                }
            }
        }

        var mygrid = {
            init: function () {
                mainGrid.dataGrid.id = 'mainGrid';
                mainGrid.dataGrid.idField = 'USERID';
                mainGrid.dataGrid.sortName = 'userCode';
                mainGrid.dataGrid.sortOrder = 'asc';
                mainGrid.dataGrid.toolbar = '#toolbar';
                mainGrid.dataGrid.onLoadSuccess = function (data) {
                    if (data.total == 0)
                        setEmptyData($(this));
                };
                mainGrid.dataGrid.loader = function (param, success, error) {
                    $('#mainGrid').datagrid('clearSelections');
                    ajax.getList(param, success);
                };
                mainGrid.dataGrid.columns = [[
                    {field: 'id', title: '员工编号', halign: 'center', align: 'center', width: 200, sortable: true},
                    {
                        field: 'englishLoginId',
                        title: '用户名',
                        halign: 'center',
                        align: 'center',
                        width: 120,
                        sortable: true
                    },
                    {field: 'name', title: '中文名', halign: 'center', align: 'center', width: 120, sortable: true},
                    {field: 'deptName', title: '部门', halign: 'center', align: 'center', width: 200},
                    {field: 'createDate', title: '入职日期', halign: 'center', align: 'center', width: 200},
                    {
                        field: 'userType', title: '用户类型', halign: 'center', align: 'center', width: 180, sortable: true,
                        formatter: function (value, row, index) {
                            var text = Tools.json.findTextById(i18n.UserTypeItems, value);
                            if (value == '0') {
                                return '<span style="color:{0}">{1}</span>'.format('blue', text);
                            }
                            return text;
                        }
                    },
                    {
                        field: 'enable', title: '用户状态', halign: 'center', align: 'center', width: 120,
                        formatter: function (value, row, index) {
                            var returnValue = '<span style="color:{0}">{1}</span>';
                            if (value == "0") {
                                return returnValue.format('blue', "正常");
                            } else if (value == "1") {
                                return returnValue.format('red', "禁止");
                            } else {
                                return "其他";
                            }
                        }
                    }
                ]];
                mainGrid.InitdataGrid();
            },
            reload: function () {
                $('#mainGrid').datagrid('reload');
            },
            selectRow: function () {
                return $('#mainGrid').datagrid('getSelected');
            }
        };

    </script>

</head>
<body>
<div class="container-wrap">
    <div id="toolbar">
        <div class="container-tit">
            <h1></h1>
        </div>
        <div class="sreach fixed">
            <div class="input-box" style="width: 360px">
                <input type="text" id="englishLoginId" name="englishLoginId" class="easyui-textbox"
                       data-options="label:'用户名:',labelWidth: 80,width:350,"/>
            </div>
            <div class="input-box">
                <input type="text" id="name" name="name" class="easyui-textbox"
                       data-options="label:'中文名:',labelWidth: 80,width:200,"/>
            </div>
            <div class="input-box">
                <select class="easyui-combobox" name="userType" id="userType"
                        data-options="  width: 200,
                                            labelWidth: 80,
                                            labelPosition: 'left',
                                            required: true,
                                            label: '用户类型:',
                                            panelHeight: 'auto',
                                            valueField: 'id',
                                            textField: 'text',
                                            editable: false,"></select>
            </div>
            <br/>
            <div class="input-box">
                <select class="easyui-combotree" name="deptId" id="deptId"
                        data-options="  width: 350,
                                            labelWidth: 80,
                                            labelPosition: 'left',
                                            required: true,
                                            label: '部门:',
                                            panelHeight: 'auto',
                                            valueField: 'id',
                                            textField: 'text',
                                            editable: false,"></select>
            </div>
            <div class="input-box">
                <input type="text" id="id" name="id" class="easyui-textbox"
                       data-options="label:'员工编号:',labelWidth: 80,width:200,"/>
            </div>
            <div class="input-box" style="width: 210px">
                <select class="easyui-combobox" name="enable" id="enable"
                        data-options="  width: 200,
                                            labelWidth: 80,
                                            labelPosition: 'left',
                                            required: true,
                                            label: '用户状态:',
                                            panelHeight: 'auto',
                                            valueField: 'id',
                                            textField: 'text',
                                            editable: false,"></select>
            </div>
            <a id="search_Link" href="#" class="easyui-linkbutton search">查询</a>
            <a id="reset_Link" href="#" class="easyui-linkbutton default">重置</a>
            <div class="bar-btn" style="position: absolute;bottom: 18px;right: 8px;">
                <a id="insert_Link" href="#" class="easyui-linkbutton insert">新增</a>
                <a id="update_Link" href="#" class="easyui-linkbutton update">修改</a>
                <a id="delete_Link" href="#" class="easyui-linkbutton delete">删除</a>
                <a id="resetPassword_Link" href="#" class="easyui-linkbutton delete">重置密码</a>
                <a id="resign_Link" href="#" class="easyui-linkbutton delete">重置签名</a>
            </div>
        </div>
    </div>
    <div id="mainGrid"></div>
</div>

</body>
</html>